package com.tensquare.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.text.SimpleDateFormat;

public class ParseJwt {
    public static void main(String[] args) {
        try {
            //获取
            Claims claims=Jwts.parser().setSigningKey("yyyy")
                    .parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2NjYiLCJzdWIiOiLlsI_lrakiLCJpYXQiOjE1NzAwODU5MTUsImV4cCI6MTU3MDA4NTk3NSwicm9sZSI6ImFkbWluIn0.4G57IQRDNMWZejnOQbrcbRMcYwk8kpnm-m9JJscX0DM").getBody();

            System.out.println("用户id："+claims.getId());
            System.out.println("用户名："+claims.getSubject());
            System.out.println("用户登录时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(claims.getIssuedAt()));
            System.out.println("过期时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(claims.getExpiration()));
            System.out.println("自定义"+claims.get("role"));
        }catch (Exception e){
            System.out.println("过期");
        }
    }
}


